package easymall.controller;

import easymall.po.Products;
import easymall.pojo.MyProducts;
import easymall.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
public class ProductController {
    @Autowired
    private ProductsService productsService;

    @PostMapping("/prodlist")
    public List<Products> prodlist(@RequestBody Map<String, Object> map){
        return productsService.prodlist(map);
    }

    @GetMapping("/oneProduct")
    public Products oneProduct(@RequestParam String pid){
        return productsService.oneProduct(pid);
    }

    @GetMapping("/proclass")
    public List<Products> proclass(@RequestParam Integer category){
        return productsService.proclass(category);
    }

    @PostMapping(value = "/save")
    public String save(MyProducts myproducts){
        return productsService.save(myproducts);
    }

    //分页相关
    @GetMapping("/getProductsByPage")
    public List<Products> getProductsByPage(@RequestParam Integer page){
        return productsService.getProductsByPage(page);
    }

    @GetMapping("/getTotalPageByProducts")
    public int getTotalPageByProducts(){
        return productsService.getTotalPageByProducts();
    }

    //商品相关
    @PostMapping(value="/updatePruduct",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String updatePruduct(MyProducts myproducts,  @RequestParam String id){
        return productsService.updatePruduct(myproducts,id);
    }

    //
    @GetMapping("/delProduct")
    public int delProduct(@RequestParam String id){
        return productsService.delProduct(id);
    }
}
